from rest_framework import pagination
from rest_framework.response import Response


class PageNumberPagination2(pagination.PageNumberPagination):
    page_size = 10  # 默认每页显示的记录数
    page_size_query_param = "size"  # URL中用于指定每页记录数的参数名
    max_page_size = 100  # 最大每页显示的记录数

    def get_paginated_response(self, data):
        return Response(
            {
                "count": self.page.paginator.count,  # 总记录数
                "next": self.get_next_link(),  # 下一页链接
                "previous": self.get_previous_link(),  # 上一页链接
                "current_page": self.page.number,  # 当前页码
                "per_page": self.page.paginator.per_page,  # 每页数量
                "total_pages": self.page.paginator.num_pages,  # 总页数
                "results": data,  # 当前页的数据
            }
        )
